<template>
  <div>
    <van-icon name="arrow-left" @click="back" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="title"
        name="title"
        label="标题"
        placeholder="标题"
        :rules="[{ required: true, message: '请填写标题' }]"
      />
      <van-field
        v-model="content"
        name="content"
        label="内容"
        placeholder="内容"
        :rules="[{ required: true, message: '请填写内容' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
    <input type="text" v-model="titleTxt" />
    <button @click="searchTitle(titleTxt)">搜索标题</button>
    <FeedList :list="list" @FeedDetail="FeedDetail" />
  </div>
</template>

<script>
import { MetroFeedbackApi } from "@/service/metro/metroservice.js";
import { SearchFeedbackApi } from "@/service/metro/metroservice.js";
import FeedList from "./component/FeedList.vue";
export default {
  data() {
    return {
      title: "",
      content: "",
      titleTxt: "",
      list: [],
    };
  },
  mounted() {
    this.searchTitle();
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    async onSubmit(info) {
      let token = window.localStorage.getItem("token");
      if (token) {
        let res = await MetroFeedbackApi(info);
        console.log(res);
        console.log(info);
      } else {
        console.log("token没有获取到");
      }
      this.searchTitle();
      this.title = "";
      this.content = "";
    },
    async searchTitle(title) {
      let token = window.localStorage.getItem("token");
      if (token) {
        let { data } = await SearchFeedbackApi({ title });
        if (data.code == 200) {
          this.list = data.rows;
        }
      }
    },
    FeedDetail(id) {
      this.$router.push({ name: "feeddetail", query: { id } });
    },
  },
  components: {
    FeedList,
  },
};
</script>

<style>
</style>